package 蓝桥.模拟赛;

public class Main4 {
    // 回溯
    int min = Integer.MAX_VALUE;
    void backtrace(int n, int t, int cost) {
        if(n>t||cost>=min)
            return;
        if(n==t) {
            min = cost;
            System.out.println(n+" "+t+" "+cost);
            return;
        }
        backtrace(n*2, t, cost+10);

        // 整数中数位最大值
        int max = 0;
        int temp = n;
        while(temp>0) {
            max = Math.max(max, temp%10);
            temp /= 10;
        }
        if(max>0)
            backtrace(n+max, t, cost+3);

        backtrace(n+1, t, cost+1);

    }
    // 改变n
    static int cost = 0;
    static int change(int op, int n) {
        int r = 0;
        if(op==2){
            r =  n*2;
            cost += 10;
        }
        if(op==1) {
            int max = 0;
            int temp = n;
            while(temp>0) {
                max = Math.max(max, temp%10);
                temp /= 10;
            }
            r =  n+max;
            cost += 3;
        }
        if(op==0) {
            r = n + 1;
            cost += 1;
        }
        System.out.println(r);
        return r;
    }
    public static void main(String[] args) {
        Main4 m = new Main4();
        m.backtrace(1, 63, 0);
        System.out.println(m.min);
//        int n = 1;
////        for (int i = 0; i < 14; i++) {
////            n = change(0, n);
////        }
//        n = change(0, n);
//        n = change(0, n);
//        n = change(1, n);
//        n = change(0, n);
//        n = change(1, n);
//        n = change(0, n);
//        System.out.printf("n=%d, cost = %d\n", n,cost);
//        n = change(2, n);
//        n = change(0, n);
//        n = change(2, n);
//        n = change(0, n);
//        n = change(2, n);
//        n = change(2, n);
//        n = change(0, n);
//        n = change(2, n);
//        n = change(2, n);
//        n = change(2, n);
//
//        System.out.println(cost);



    }
}
